﻿<Window x:Class="PBS.APP.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        Title="Portable Basemap Server v3.0" Height="400" Width="850" Icon="/PortableBasemapServer;component/Images/Map.png" WindowStyle="SingleBorderWindow" WindowStartupLocation="CenterScreen" SizeToContent="Manual" ResizeMode="CanResize" FontFamily="Verdana" FontSize="12">
    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="20" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <!--menu-->
        <Menu Grid.Row="0" HorizontalAlignment="Stretch">
            <MenuItem x:Name="menuConfiguration" Header="{DynamicResource menuConfiguration}">
                <MenuItem x:Name="miConfigurationFile" Header="{DynamicResource miConfigurationFile}" Command="{Binding CMDClickMenuItem}" CommandParameter="miConfigurationFile" />
                <MenuItem x:Name="miLoadLastConfiguration" Header="{DynamicResource miLoadLastConfiguration}" IsCheckable="True" IsChecked="{Binding IsLoadLastConfiguration,Mode=TwoWay}" Command="{Binding CMDClickMenuItem}" CommandParameter="miLoadLastConfiguration" />
                <MenuItem x:Name="miRunAsWindowsService" Header="{DynamicResource miRunAsWindowsService}" IsCheckable="True" IsChecked="{Binding IsRunAsWindowsService,Mode=TwoWay}" Command="{Binding CMDClickMenuItem}" CommandParameter="miRunAsWindowsService" />
            </MenuItem>
            <MenuItem x:Name="miSetBingAPIKey" Header="{DynamicResource miSetBingAPIKey}" Command="{Binding CMDClickMenuItem}" CommandParameter="miSetBingAPIKey" />
            <MenuItem Header="{Binding StrMemCacheMenuHeader}">
                <MenuItem x:Name="miEnableMemCache" IsCheckable="True" Header="{DynamicResource miEnableMemCache}" Command="{Binding CMDClickMenuItem}" CommandParameter="miEnableMemCache" IsChecked="{Binding IsMemCacheEnabled,Mode=TwoWay}" />
                <MenuItem x:Name="miClearMemoryCache" Header="{DynamicResource miClearMemoryCache}" Command="{Binding CMDClickMenuItem}" CommandParameter="miClearMemoryCache" IsEnabled="{Binding IsMemCacheEnabled}" />
            </MenuItem>
            <MenuItem Header="{DynamicResource menuFormatConvert}">
                <MenuItem x:Name="miArcGISToMBTiles" Header="{DynamicResource miArcGISToMBTiles}" Command="{Binding CMDClickMenuItem}" CommandParameter="miArcGISToMBTiles" />
                <MenuItem x:Name="miOnlineToMBTiles" Header="{DynamicResource miOnlineToMBTiles}" Command="{Binding CMDClickMenuItem}" CommandParameter="miOnlineToMBTiles" />
            </MenuItem>
            <MenuItem Header="{DynamicResource menuAppearance}">
                <MenuItem x:Name="miLanguage" Header="{DynamicResource miLanguage}" Command="{Binding CMDClickMenuItem}" CommandParameter="miLanguage" />
                <MenuItem x:Name="miShowInSysTray" Header="{DynamicResource miShowInSysTray}" Command="{Binding CMDClickMenuItem}" CommandParameter="miShowInSysTray" IsCheckable="True" IsChecked="{Binding IsShowInSysTray,Mode=TwoWay}" />
            </MenuItem>
            <MenuItem x:Name="miAbout" Header="{DynamicResource menuAbout}"  Command="{Binding CMDClickMenuItem}" CommandParameter="miAbout" />
        </Menu>
        <!--Service Parameter and Service Detail-->
        <Grid Background="Azure" Grid.Row="1">
            <StackPanel>
                <!--parameters-->
                <StackPanel Background="SkyBlue">
                   <!--Tile Source Type-->
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{DynamicResource tbDataSourceType}" Padding="0,0,10,0" VerticalAlignment="Center" />
                        <ComboBox x:Name="cmbboxDataSourceType" Width="Auto" ItemsSource="{Binding DataSourceTypes,Mode=OneWay}" SelectedItem="{Binding ValueDataSourceType,Mode=TwoWay}" />
                        <Button x:Name="btnArcGISDynamicMapServiceParams" Content="{DynamicResource btnArcGISDynamicMapServiceParams}" Visibility="{Binding IsAGSDMSParamsButtonVisible,Mode=OneWay}" Command="{Binding CMDArcGISDynamicMapServiceParams}"/>
                    </StackPanel>                    
                    <!--Tile Source Path-->
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="100" />
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Column="0" Text="{DynamicResource tbDataSourcePath}" Padding="0,0,10,0" VerticalAlignment="Center" />
                        <TextBox Grid.Column="1" x:Name="textboxDataSourcePath" Text="{Binding ValueDataSourcePath,Mode=TwoWay}" Height="{Binding DataSourcePathTBHeight,Mode=OneWay}" IsEnabled="{Binding IsDataSourcePathTBEnabled,Mode=OneWay}" AcceptsReturn="True" TextWrapping="Wrap" ScrollViewer.VerticalScrollBarVisibility="Auto">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="GotFocus">
                                    <i:InvokeCommandAction Command="{Binding CMDGotAndLostFocus}"  
                             CommandParameter="textboxDataSourcePath_got"/>
                                </i:EventTrigger>
                                <i:EventTrigger EventName="LostFocus">
                                    <i:InvokeCommandAction Command="{Binding CMDGotAndLostFocus}"  
                             CommandParameter="textboxDataSourcePath_lost"/>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </TextBox>
                        <Button Grid.Column="2" x:Name="btnBrowse" Content="{DynamicResource btnBrowse}" Command="{Binding CMDClickBrowseButton}" Visibility="{Binding IsBrowseButtonVisible,Mode=OneWay}" IsEnabled="{Binding IsBrowseButtonEnabled,Mode=OneWay}" />
                    </Grid>
                    <!--Tiling Scheme, Only visible when source type is Raster or ArcGISDynamicService-->
                    <StackPanel x:Name="spTilingScheme" Orientation="Horizontal" Visibility="{Binding IsTilingSchemePanelVisible,Mode=OneWay}">
                        <TextBlock Text="{DynamicResource tbTilingScheme}" Padding="0,0,10,0" VerticalAlignment="Center" />
                        <TextBox x:Name="textboxTilingSchemeFile" Text="{Binding ValueTilingSchemeFilePath,Mode=OneWay}" Width="500" IsReadOnly="True" />
                        <CheckBox x:Name="chkboxUsingGoogleTilingScheme" Content="{DynamicResource chkboxUsingGoogleTilingScheme}" IsChecked="{Binding IsUsingGoogleTilingSchemeChecked,Mode=TwoWay}" Command="{Binding CMDClickIsUsingGoogleTilingScheme}" VerticalAlignment="Center" />
                    </StackPanel>
                    <!--Port, ServiceName-->
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{DynamicResource tbServicePort}" Padding="0,0,10,0" VerticalAlignment="Center" />
                        <TextBox x:Name="textboxServicePort" Text="{Binding ValueServicePort,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Width="50">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="LostFocus">
                                    <i:InvokeCommandAction Command="{Binding CMDGotAndLostFocus}"  
                             CommandParameter="textboxServicePort_lost"/>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </TextBox>
                        <TextBlock Text="{DynamicResource tbServiceName}" Padding="0,0,10,0" VerticalAlignment="Center" />
                        <TextBox x:Name="textboxServiceName" Text="{Binding ValueServiceName,Mode=TwoWay}" IsEnabled="{Binding IsServiceNameTBEnabled,Mode=OneWay}" Width="150">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="LostFocus">
                                    <i:InvokeCommandAction Command="{Binding CMDGotAndLostFocus}"  
                             CommandParameter="textboxServiceName_lost"/>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </TextBox>
                        <TextBlock Text="{DynamicResource tbVisualStyle}" VerticalAlignment="Center" />
                        <ComboBox x:Name="cmbboxVisualStyle" Width="150" ItemsSource="{Binding VisualStyles,Mode=OneWay}" SelectedItem="{Binding ValueVisualStyle,Mode=TwoWay}" />
                    </StackPanel>
                    <!--additional options-->
                    <StackPanel Orientation="Horizontal" Height="24">
                        <CheckBox x:Name="chkboxAllowMemoryCache" Content="{DynamicResource chkboxAllowMemoryCache}" VerticalAlignment="Center" Margin="0,0,0,0" IsChecked="{Binding IsAllowMemoryCache,Mode=TwoWay}" />
                        <CheckBox x:Name="chkboxDisableClientCache" Content="{DynamicResource chkboxDisableClientCache}" VerticalAlignment="Center" Margin="20,0,0,0" IsChecked="{Binding IsDisableClientCache,Mode=TwoWay}" />
                        <CheckBox x:Name="chkboxDisplayNoDataTile" Content="{DynamicResource chkboxDisplayNoDataTile}" VerticalAlignment="Center" Margin="20,0,0,0" IsChecked="{Binding IsDisplayNoDataTile,Mode=TwoWay}" />                        
                    </StackPanel>
                </StackPanel>
                <!--service addresses-->
                <DockPanel>
                    <StackPanel Orientation="Vertical" Background="MediumAquamarine">
                        <!--ip address-->
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{DynamicResource tbLocalIPAddress}" VerticalAlignment="Center" />
                            <ComboBox x:Name="cmbboxIPAddress" Width="150" ItemsSource="{Binding IPAddresses,Mode=OneWay}" SelectedItem="{Binding ValueIPAddress,Mode=TwoWay}" />
                        </StackPanel>
                        <!--arcgis rest url-->
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="140" />
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0" Text="{DynamicResource tbArcGISRESTURL}" Padding="0,0,10,0" VerticalAlignment="Center" />
                            <TextBox Grid.Column="1" x:Name="textboxServiceArcGIS" Text="{Binding StrURLArcGIS,Mode=OneWay}" IsReadOnly="True" />
                            <Button Grid.Column="2" x:Name="btnCopyArcGIS" Content="{DynamicResource btnCopyArcGIS}" Command="{Binding CMDClickCopyUrlButton}" CommandParameter="ArcGIS" />
                        </Grid>
                        <!--wmts url-->
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="140" />
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0" Text="{DynamicResource tbWMTSURL}" Padding="0,0,10,0" VerticalAlignment="Center" />
                            <TextBox Grid.Column="1" x:Name="textboxServiceWMTS" Text="{Binding StrURLWMTS,Mode=OneWay}" IsReadOnly="True" />
                            <Button Grid.Column="2" x:Name="btnCopyWMTS" Content="{DynamicResource btnCopyArcGIS}" Command="{Binding CMDClickCopyUrlButton}" CommandParameter="WMTS" />
                        </Grid>
                    </StackPanel>                    
                </DockPanel>
            </StackPanel>            
        </Grid>
        <!--<GridSplitter Height="5" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" />-->
        <!--Button Row-->
        <Grid Grid.Row="2">
            <StackPanel Orientation="Horizontal">
                <Button x:Name="btnStartService" Content="{DynamicResource btnStartService}" Command="{Binding CMDClickServiceButton}" CommandParameter="START" />
                <Button x:Name="btnDeleteService" Content="{DynamicResource btnDeleteService}" Command="{Binding CMDClickServiceButton}" CommandParameter="DELETE" />
                <TextBlock Text="{DynamicResource tbDoubleClickToPreview}" VerticalAlignment="Center" Margin="200,0,0,0" />
            </StackPanel>
        </Grid>
        <!--Service List-->
        <Grid Grid.Row="3" Background="Azure">
            <!--original, not mvvm binding-->
            <ListView x:Name="lvServices" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" GridViewColumnHeader.Click="lvServices_GridViewColumnHeader_Click" SelectedItem="{Binding SelectedPBSService,Mode=TwoWay}" ItemsSource="{Binding PBSServices}">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="MouseDoubleClick">
                        <i:InvokeCommandAction Command="{Binding CMDDoubleClickService}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
                <ListView.View>
                    <GridView>
                        <GridViewColumn Width="150" Header="{DynamicResource gvheaderServiceName}" DisplayMemberBinding="{Binding ServiceName}" />
                        <GridViewColumn Width="100" Header="{DynamicResource gvheaderServicePort}"  
           DisplayMemberBinding="{Binding Port}" />
                        <GridViewColumn Width="150" Header="{DynamicResource gvheaderDataSourceType}"
           DisplayMemberBinding="{Binding DataSource.Type}" />
                        <GridViewColumn Width="140">
                            <GridViewColumnHeader>
                                <TextBlock TextWrapping="Wrap" Text="{DynamicResource gvheaderOutputCount}" />
                            </GridViewColumnHeader>
                            <GridViewColumn.DisplayMemberBinding>
                                <MultiBinding StringFormat="{}{0} ({1}/{2}/{3})" Mode="OneWay">
                                    <Binding Path="LogInfo.OutputTileCountTotal" />
                                    <Binding Path="LogInfo.OutputTileCountMemcached" />
                                    <Binding Path="LogInfo.OutputTileCountFileCache" />
                                    <Binding Path="LogInfo.OutputTileCountDynamic" />
                                </MultiBinding>
                            </GridViewColumn.DisplayMemberBinding>
                        </GridViewColumn>
                        <GridViewColumn Width="120" Header="{DynamicResource gvheaderSecondPerTile}" DisplayMemberBinding="{Binding LogInfo.SPT, StringFormat=N3}" />
                        <GridViewColumn Width="150" Header="{DynamicResource gvheaderLastClientIP}" DisplayMemberBinding="{Binding LogInfo.LastRequestClientIP}" />
                    </GridView>
                </ListView.View>
            </ListView>
        </Grid>
    </Grid>
</Window>
